import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";
// import Cart from '../views/Cart.vue'
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/home"
  },
  {
    path: "/home",
    name: "Home",
    component: Home,
    meta: {
      keepAlive: true,
      loginStatus: true
    }
  },
  {
    path: "/cart",
    name: "cart",
    component: () => import("../views/Cart.vue"),
    // beforeEnter: (to, from, next) => { //路由配置项中的钩子函数
    // ...
    // }
  },
  {
    path: "/about",
    name: "About",
    component: () => import("../views/About.vue"),
    children: [
      {
        path: "car", name: "Car", component: () => import("../views/aboutView/Car.vue")
      },
      {
        path: "news", name: "News", component: () => import("../views/aboutView/News.vue")
      }
    ]
  }
];

const router = new VueRouter({
  mode: "hash", //hash  地址栏显示#  基于window.onhashchange事件  history  history.pushState() 
  //  process.env.NODE_ENV==dev    开发环境
  // process.env.NODE_ENV=product  生产环境
  base: process.env.NODE_ENV == 'dev' ? process.env.BASE_URL : "http://127.0.0.1:8888",
  routes
});

export default router;
